#if !defined(AFX_MDMGRF_H__222AA709_D9C4_419D_9920_CC3A54FE0CAD__INCLUDED_)
#define AFX_MDMGRF_H__222AA709_D9C4_419D_9920_CC3A54FE0CAD__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "CommonDef.h"

#include "GrfData.h"
#include "DblScrollBar.h"

/* Handle to a DIB */
DECLARE_HANDLE(HDIB);

/* DIB Macros*/
#define IS_WIN30_DIB(lpbi)  ((*(LPDWORD)(lpbi)) == sizeof(BITMAPINFOHEADER))
#define RECTWIDTH(lpRect)     ((lpRect)->right - (lpRect)->left)
#define RECTHEIGHT(lpRect)    ((lpRect)->bottom - (lpRect)->top)

// WIDTHBYTES performs DWORD-aligning of DIB scanlines.  The "bits"
// parameter is the bit count for the scanline (biWidth * biBitCount),
// and this macro returns the number of DWORD-aligned bytes needed
// to hold those bits.
#define WIDTHBYTES(bits)    (((bits) + 31) / 32 * 4)
#define DIB_HEADER_MARKER   ((WORD) ('M' << 8) | 'B')

#define MAX_STARSNUM   20
#define NORM_GRAFT        

typedef enum _enummdmgrftype{
	GT_CURVE=0,
		GT_STARS=1
}MGTYPE;

typedef struct {
	double i;
	double q;
} COMPLEX;

#define SQR(a) (a*a)

/////////////////////////////////////////////////////////////////////////////
// CMdmGrf window
class CMdmGrf : public CEdit
{
	// Construction
public:
	CMdmGrf();
	
	// Attributes
public:
	
protected:
	// template list containing tab information
	CArray <CGrfData*, CGrfData*> MG_graph;
	CDoubleScrollBar              MG_DblScrollBar;        // The horizontal scroll bar (used with FTS_XT_HSCROLL)
	
	typedef CArray <COMPLEX, COMPLEX> Array_point;
	Array_point m_aPoint;
	BOOL m_bDataNorm;
	int m_niiMax;
	
	CFont		m_LitFont;			// default font created by control if m_pFont is NULL
	
	MGTYPE      CS_eType;
	
	double      CS_dValue;
	unsigned char *CS_pRaws[MAX_STARSNUM];
	int  CS_Count;
	int  CS_Pointer;
	double      MG_Width;
	double      MG_Height;
	
	double      MG_hBuoy;
	double      MG_vBuoy;
	
	int         MG_ScrollPos;
	int         MG_MaxPos;
	
	CPoint   MG_point;
	
	CPen     pen_vFrm;
	CPen     pen_vDot;
	CPen    *pen_vOld;
	
	// Operations
public:
	bool   RealtimeAppeal(HSM_ITEM *cgInfo,int agPort);
	bool RubawayPlots();
	void   RepealDevice(int rgPort);
	
	void   AllCalculate();
	void   SoloCalculate(CGrfData *drManner,CRect rcLt);
	
	void   Sugarup(double iValue,HSM_ITEM *cgInfo,unsigned char *suRaw);
	void   ScratchPoint(double iDel,HSM_ITEM *cgInfo);
	void   DrawConstellation(HSM_ITEM *cgInfo,double iValue,unsigned char *suRaw);
	
	
	void   ToSwell();
	void   ToShrink();
	void   ToZoomin();
	void   ToZoomout();
	
	// export chart
	virtual bool CopyToFile( CString sFile );
	virtual bool CopyToFile();
	virtual bool CopyToClipboard();
	
protected:
    int    AltCoordinate(CGrfData *riCfg,double dbRi);
    int    RetrieveInfo(CGrfData *riCfg,int riItem);
	void   fnPaint(CDC &paintDC);
	void   csPaint(CDC *paintDC);
	void   prPaint(CDC &paintDC);
	
	void  GetPoint();
	double csquare(COMPLEX a);
	void norm_by_num();
	void normcpx();
	
    virtual BOOL WINAPI SaveDIB (HDIB hDib, CFile& file);									// the clipboard
	virtual HANDLE      DDBToDIB( CBitmap& bitmap, DWORD dwCompression, CPalette* pPal );	// functions used to
	virtual WORD WINAPI PaletteSize( LPSTR lpbi );											// save the chart in
	virtual WORD WINAPI DIBNumColors(LPSTR lpbi);											// a BMP file or in
	
	// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CMdmGrf)
	//}}AFX_VIRTUAL
	
	// Implementation
public:
	virtual ~CMdmGrf();
	
	// Generated message map functions
protected:
	//{{AFX_MSG(CMdmGrf)
	afx_msg void OnPaint();
	afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
	//}}AFX_MSG
	
	DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_MDMGRF_H__222AA709_D9C4_419D_9920_CC3A54FE0CAD__INCLUDED_)
